<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="com.carrentalssm.service.CarListService"%>
<%@page import="java.sql.Date"%>
<%@page import="com.carrentalssm.entity.CarList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>提交订单</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/frame/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/css/bootstrap.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="css/common.css">
</head>
<style type="text/css">
	body{
		background-image: url("images/background.jpg");
		overflow: hidden;
	}
	.login-div{
		background: rgba(217, 237, 247);
		width: 600px;
		box-sizing: border-box;
		margin: 0px auto;
		padding: 20px 40px;
	}
	.login-title{
		text-align: center;
		font-size: 30px;
	}
	.form-item{
		box-sizing: border-box;
		width: 100%;
		height: 35px;
		margin-top: 15px;
		padding: 0px 5px;
	}
</style>
<body>
	<%
	Object loginUser = request.getSession().getAttribute("user");
	if (loginUser == null) {
		response.sendRedirect(request.getContextPath()+"/login.jsp");
		return;
	}
	%>
	<div class="head">
		<div class="head-content">
			<h2>小彭租车！</h2>
			<a href="<%=request.getContextPath() %>/index.jsp">首页</a>
			<a href="<%=request.getContextPath() %>/carRentalList.jsp">我的订单</a>
			<a href="<%=request.getContextPath() %>/userUpdate.jsp">个人信息</a>
			<a href="<%=request.getContextPath() %>/logout">退出</a>
		</div>
	</div>
	<div class="main">
		<%
			String carId = request.getParameter("id");
			int num = Integer.parseInt(request.getParameter("num"));
			
			WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
			CarListService carListService= (CarListService) context.getBean("carListService");
			CarList carList = carListService.selectById(carId);
			
			Date startDate = Date.valueOf(request.getParameter("startDatetime"));
			Date endDate = Date.valueOf(request.getParameter("endDatetime"));
			
			int day = (int) ((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)); // 计算天数
			
			Double rentalTotal = carList.getPrice() * num * day;
			
		%>
		<form class="main-content" action="<%=request.getContextPath() %>/carRental/add" method="post">
			<input name="carId" type="text" hidden="hidden" value="<%=carId %>">
			<h2>确认提交订单</h2>
			<table>
				<tr>
					<td>型号</td>
					<td><%=carList.getModel() %></td>
				</tr>
				<tr>
					<td>数量</td>
					<td>
						<input class="form-control" style="width: 200px" name="rentalNum" type="number" readonly="readonly" value="<%=num %>">
					</td>
				</tr>
				<tr>
					<td>开始时间</td>
					<td>
						<input class="form-control" style="width: 200px" name="rentalStartDatetime" readonly="readonly" type="date" value="<%=startDate %>">
					</td>
				</tr>
				<tr>
					<td>结束时间</td>
					<td>
						<input class="form-control" style="width: 200px" name="rentalEndDatetime" readonly="readonly" type="date" value="<%=endDate %>">
					</td>
				</tr>
				<tr>
					<td>总价</td>
					<td>
						<input class="form-control" style="width: 200px" name="rentalTotal" readonly="readonly" type="text" value="<%=rentalTotal %>">
					</td>
				</tr>
				<tr>
					<td>
						<button class="select-button btn btn-success">提交订单</button>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>